/* 
 *  Syntelos XB
 *  Copyright (C) 2006 John Pritchard.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307 USA
 */

package syntelos.xb.at;

/** 
 * <p> {@link Line} number table attribute. </p>
 * 
 * @author jdp
 */
public final class LineNumberTable 
    extends syntelos.xb.Attribute
{
    public final static java.lang.String ATNAME = "LineNumberTable";
    public final static syntelos.iou.dom.Name NAME = new syntelos.iou.dom.impl.Name(ELEMENT_NODE,"http://www.syntelos.org/xb/at","xat:line-number-table");

    public LineNumberTable(org.w3c.dom.Document doc, syntelos.iou.dom.Name name){
        super(doc,name);
    }
    public LineNumberTable(org.w3c.dom.Document doc){
        this(doc,NAME);
    }
    public LineNumberTable(){
        this(DOC_NIL);
    }

    public syntelos.iou.dom.Node compile(){

        this.getAttributeName().setNodeValue("utf8:LineNumberTable");

        return super.compile();
    }
    protected syntelos.xb.Attributes getAttributeCodeAttributes(){
        return (syntelos.xb.Attributes)this.getParentNode();
    }
    public Code getAttributeCode(){
        return (Code)(this.getParentNode().getParentNode());
    }
    public LocalVariableTable getAttributeLocalVariableTable(){
        return this.getAttributeCode().getAttributeLocalVariableTable();
    }
    public syntelos.xb.op.Code getOpCode(){
        return this.getAttributeCode().getOpCode();
    }
    public syntelos.xb.Method getMethod(){
        return this.getAttributeCode().getMethod();
    }
    public int atlen(){
        int count = this.countChildNodes();
        return (2 + (4 * count));
    }
    public void readCF(syntelos.xb.IO.Uri src, syntelos.xb.CF.Reader reader)
        throws java.io.IOException
    {
        int at_length = reader.readInt();
        int count = reader.readUnsignedShort();
        Line line;
        for (int cc = 0; cc < count; cc++){
            line = new Line();
            this.appendChild(line);
            line.readCF(src,reader);
        }
    }
    public void writeCF(syntelos.xb.IO.Uri dst, syntelos.xb.CF.Writer writer)
        throws java.io.IOException
    {
        this.getAttributeName().writeCF(dst,writer);
        int at_len = this.atlen();
        writer.writeInt(at_len);
        int count = this.countChildNodes();
        writer.writeShort(count);
        if (0 < count){
            org.w3c.dom.NodeList children = this.getChildNodes();
            Line line;
            for (int cc = 0; cc < count; cc++){
                line = (Line)children.item(cc);
                line.writeCF(dst,writer);
            }
        }
    }
}
